package com.cowin.utils;

import java.lang.reflect.Method;

/**
 * Copyright (C), 1998-2019, 奇瑞信息
 *
 * @author : 于超
 * @Date: 2019/11/26 10:02
 * @Description:
 */
public class ReflexUtil {
   public Object invokeMethod(String propertiesName, Object object) {
       if(object==null){
           return null;
       }
       if(!propertiesName.contains(".")){
           String methodName = "get"+getMethodName(propertiesName);
           try {
               Method method = object.getClass().getMethod(methodName);
               return method.invoke(object);
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
       return  null;
   }

   private String getMethodName(String fildeName){
       byte[] items = fildeName.getBytes();
       items[0] = (byte)((char)items[0]-'a'+'A');
       return new String(items);
   }
}
